import Vue from 'vue'
import Vuex from 'vuex'
// 引入 axios
import axios from 'axios'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        token: '',
        checkeds: [],
        scroll: 0,
        setting: {
            //显示头尾
            show_xheader: true,
            show_xfooter: true,
            //页面是否加载完成
            page_loading: false,
            width_s: document.documentElement.clientWidth,
        },
        apiSetting: {
            'time_stamp': '',
            'nonce_str': '',
            'signature': '',
            'app_key': '',
            'app_secret': '',
            'agent_id': '',
            'corp_id': '' //
        }
    },
    getters: {},
    mutations: {
        setToken(state, token) {
            state.token = token
        },
        setScroll(state, scroll) {
            state.scroll = scroll
        },

        setCheckeds(state, checkeds) {
            state.checkeds = checkeds
        },
        setSettings(state, setting) {
            for (var key in state.setting) {
                if (setting.hasOwnProperty(key)) {
                    state.setting[key] = setting[key]
                }
            }
        },
        setApiSetting(state, setting) {
            for (var key in state.apiSetting) {
                if (setting.hasOwnProperty(key)) {
                    state.apiSetting[key] = setting[key]
                }
            }
        }
    },
    actions: {
        // 封装一个 ajax 方法
        saveForm(aa, bb) {

            axios({
                method: 'post',
                url: '/user',
                data: bb
            }).then(() => {
            }).catch(() => {
                this.commit('setToken', '21111')
                // this.commit('setSettings',{'show_xheader':false}); //设置头部导航为不显示
            })
        }
    }
})

export default store